from src.model.read_model import fetch_reference_range_by_hospital_project


class ReadMinMax(object):
    def __init__(self, hospital_id, project_id):
        self.index_reference_range_dict = \
            fetch_reference_range_by_hospital_project(hospital_id=hospital_id, project_id=project_id)

    def read_index_min_max(self, index_id, v):
        index_reference_range = self.index_reference_range_dict.get(index_id)

        range_list = index_reference_range.split('-') if '-' in index_reference_range else None
        if range_list:
            if '阴性' in index_reference_range or (len(range_list) <= 1):
                is_abnormal = False if v == '-' else True
            else:
                min_value, max_value = range_list
                if v:
                    is_abnormal = False if float(min_value) <= float(v) <= float(max_value) else True
                else:
                    is_abnormal = False
        else:
            is_abnormal = False
        return is_abnormal
